<style scoped>
</style>
<template>
  <component v-if="template" :is="template" :__iframe="__iframe" :model="model" :this_action="this_action" />
</template>
<script>
import edit_common from '@/components/model_base/edit_common.vue'
import {S94Model} from "@/js/S94Model.js";
import {error_back} from "@/js/tool.js";

export default {
  components: {edit_common},
  props: ['__iframe'],
  data(){
    let init_data = this.init();
    return {
      model: init_data.model,
      this_action: init_data.this_action,
      template: init_data.template,
    }
  },
  methods:{
    /**
     * @returns {{model:S94Model, this_action:Object, template:string}}
     */
    init(){
      let res = {}
      //模型解析
      let model_name = this.$get('model_name');
      res.model = S94Model.find(model_name);
      if (!res.model) {
        error_back(`参数错误：model_name=${model_name}`);
        return res;
      }
      // 操作解析
      let action = this.$get('action', '');
      let type = this.$get('is_info') ? 'info' : (this.$get('id')>0?'edit':'add');
      res.this_action = res.model.findActionAdmin(action, type);
      if (!res.this_action) {
        error_back(`参数错误：action=${action}`);
        return res;
      }
      // 模板
      let def_template = 'edit_common';
      res.template = res.this_action.template || res.this_action.config.template || def_template;

      console.log(res)
      return res;
    }
  },
  computed:{},
  mounted(){
  }
}
</script>